﻿// 文件使用MiniExcel源码， 使用时需遵循其 Apache License 2.0
// 修改摘要通知： 删除异步、Task等net2.0中不支持的内容，替换原先C#自带的zip处理方式，改用yacomp 进行解压缩。
using System;
using System.IO;
using System.Text;

namespace ExcelConfig.Zip
{
    using yacomp;
    using yacomp.os;

    internal class MiniExcelZipArchive : IDisposable
    {
        internal YacompZip zip;
        internal YacompStorage storage;
        internal Stream stream;
        public MiniExcelZipArchive(Stream stream, bool leaveOpen, Encoding entryNameEncoding)
        {
            if (stream.Length == 0)
            {
                zip = new YacompZip();
                this.stream = stream;
            }
            else zip = new YacompZip(stream, leaveOpen);
            storage = zip.GetStorage();
        }

        internal void Save()
        {
            if (stream.Length == 0) zip.ToStream(stream);
        }

        public YacompFile CreateEntry(string path)
        {
            return storage.OperateFile(path);
        }
        public void Dispose()
        {
            zip.Dispose();
            GC.SuppressFinalize(this);
        }
    }
}
